﻿using System;
using System.Data;
using System.Collections.Generic;
using eTMS.Controllers.SoNoSinhVienService;
namespace eTMS.Controllers{
public class SoNoSinhVienControllerBase : CommonController{
	public SoNoSinhVienControllerBase()
		: base()
	{	
		this.dao = new SoNoSinhVienServiceClient();
	}
	~SoNoSinhVienControllerBase(){
		if(dao.State==System.ServiceModel.CommunicationState.Opened)try{dao.Close();}catch{}
	}
	private DataTable _Table;
	private SoNoSinhVienEntity oSoNoSinhVien;	
	public SoNoSinhVienEntity SoNoSinhVienObject{
		get{
			return oSoNoSinhVien;
		}
		set{
			oSoNoSinhVien=value;
		}
	}
	protected SoNoSinhVienServiceClient dao;
	public DataTable Table{
		get{
			return _Table;
		}
        set
        {
            _Table = value;
        }
	}
	
	public void AddIndexToTable(){
		this.AddIndexToTable(_Table);
	}
	public void ResetTableIndex(){
		this.ResetTableIndex(_Table);
	}
	public bool AddNew(){
		if(oSoNoSinhVien==null)return false;
		bool result=true;
		try{
			oSoNoSinhVien = dao.SaveRet(oSoNoSinhVien);
		}
		catch{
			result=false;
		}
		
		return result;
	}
	public bool Update(){
		if(oSoNoSinhVien==null)return false;
		return dao.Update(oSoNoSinhVien);
	}
	public bool Delete(){
		if(oSoNoSinhVien==null)return false;
		bool retvalue = dao.Delete(oSoNoSinhVien);
		
		return retvalue;
	}
	public bool DeleteByID(Int32 SoNoSinhVien_ID){
		bool retvalue = dao.DeleteByID(SoNoSinhVien_ID);		
		
		return retvalue;
	}
	public void ResetObject(){
		this.oSoNoSinhVien = new SoNoSinhVienEntity();
	}
	   
    //Copy data from data row in grid to object
    public SoNoSinhVienEntity MapDataRowToObject(DataRow row){
		SoNoSinhVienEntity o = new SoNoSinhVienEntity();
		 if(!row.IsNull("SoNoSinhVien_ID"))
			o.SoNoSinhVien_ID=ConvertInt(row["SoNoSinhVien_ID"]);
		 if(!row.IsNull("NgayCN"))
			o.NgayCN=ConvertDateTime(row["NgayCN"]);
		 o.GhiChu=Convert.ToString(row["GhiChu"]);
		 if(!row.IsNull("NamHoc_ID"))
			o.NamHoc_ID=ConvertInt(row["NamHoc_ID"]);
		 if(!row.IsNull("HocKy_ID"))
			o.HocKy_ID=ConvertInt(row["HocKy_ID"]);
		 if(!row.IsNull("SinhVien_ID"))
			o.SinhVien_ID=(Int32)(row["SinhVien_ID"]);
		 if(!row.IsNull("SoNoSinhVien_ID"))
		    o.SoNoSinhVien_ID=(Int32)(row["SoNoSinhVien_ID"]);
		 return o;
    }
	//Copy data from object to data row in grid    
    public void MapObjectToDataRow(SoNoSinhVienEntity o,DataRow row){
		row["SoNoSinhVien_ID"]=o.SoNoSinhVien_ID;
		row["NgayCN"]=o.NgayCN;
		row["GhiChu"]=o.GhiChu;
		row["NamHoc_ID"]=o.NamHoc_ID;
		row["HocKy_ID"]=o.HocKy_ID;
		row["SinhVien_ID"]=o.SinhVien_ID;
		row["SoNoSinhVien_ID"]=o.SoNoSinhVien_ID;
    }
    public void MapObjectToDataRow(DataRow row){
		this.MapObjectToDataRow(this.SoNoSinhVienObject,row);
    }
	public void LoadObject(Int32 SoNoSinhVien_ID){
			oSoNoSinhVien=this.dao.SelectOne(SoNoSinhVien_ID);		
			
	}
}
}
